﻿/*
自定弹窗类 
*/

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
namespace Common
{
    public delegate void Confim();
    public delegate void Cancel();
    public class MessageBox
    {
        static GameObject Messagebox;
        static int Result = -1;
        public static Confim confim;
        public static Cancel cancel;
        public static string TitleStr;  //标题
        public static string ContentStr;//内容
        public static string SureStr = "确定"; //确定按钮文字
        public static string CancelStr = "取消"; //取消按钮文字


        public static void Show(string content)
        {
            ContentStr = "    " + content;
            //Messagebox = (GameObject)Resources.Load("Prefab/Background");//加载背景
            //Messagebox = GameObject.Instantiate(Messagebox, GameObject.Find("MessageCanvas").transform) as GameObject;
            Transform RootUI = GameObject.Find("UI_Canvas").transform;
            Messagebox = GameObject.Instantiate(RootUI.Find("MsgBox").gameObject) as GameObject; //实例化一个窗口     
            Messagebox.transform.localScale = new Vector3(1, 1, 1);
            //Messagebox.GetComponent<RectTransform>().anchoredPosition = Vector3.zero;
            //Messagebox.GetComponent<RectTransform>().offsetMin = Vector2.zero;
            //Messagebox.GetComponent<RectTransform>().offsetMax = Vector2.zero;
            Time.timeScale = 1;
        }
        public static void Show(string title, string content)
        {
            TitleStr = title;
            ContentStr = "    " + content;
            Transform RootUI = GameObject.Find("UI_Canvas").transform;
            Messagebox = GameObject.Instantiate(RootUI.Find("MsgBox").gameObject) as GameObject; //实例化一个窗口          
            Messagebox.transform.localScale = new Vector3(1, 1, 1);
            Messagebox.SetActive(true);
            Messagebox.GetComponent<RectTransform>().anchoredPosition = Vector3.zero;
            Messagebox.GetComponent<RectTransform>().offsetMin = Vector2.zero;
            Messagebox.GetComponent<RectTransform>().offsetMax = Vector2.zero;
            Time.timeScale = 1;
        }

        public static void Show(string title, string content, string suretxt)
        {
            TitleStr = title;
            ContentStr = "    " + content;
            SureStr = suretxt;
            Transform RootUI = GameObject.Find("UI_Canvas").transform;
            Messagebox = GameObject.Instantiate(RootUI.Find("MsgBox").gameObject) as GameObject; //实例化一个窗口          
            Messagebox.transform.localScale = new Vector3(1, 1, 1);
            Messagebox.SetActive(true);
            Messagebox.GetComponent<RectTransform>().anchoredPosition = Vector3.zero;
            Messagebox.GetComponent<RectTransform>().offsetMin = Vector2.zero;
            Messagebox.GetComponent<RectTransform>().offsetMax = Vector2.zero;
            Button Sure = Messagebox.GetComponent<UIMessage>().Sure;
            Button Cancel = Messagebox.GetComponent<UIMessage>().Cancel;
            Cancel.gameObject.SetActive(false);
            Sure.GetComponent<RectTransform>().position = new Vector2(0, -90);
            Time.timeScale = 1;
        }

        public static void Show(string title, string content, string suretxt, string canceltxt)
        {
            TitleStr = title;
            ContentStr = "    " + content;
            SureStr = suretxt;
            CancelStr = canceltxt;
            //BtnStyle = stylenum;
            Transform RootUI = GameObject.Find("UI_Canvas").transform;
            Messagebox = GameObject.Instantiate(RootUI.Find("MsgBox").gameObject) as GameObject; //实例化一个窗口          
            Messagebox.transform.localScale = new Vector3(1, 1, 1);
            Messagebox.SetActive(true);
            Messagebox.GetComponent<RectTransform>().anchoredPosition = Vector3.zero;
            Messagebox.GetComponent<RectTransform>().offsetMin = Vector2.zero;
            Messagebox.GetComponent<RectTransform>().offsetMax = Vector2.zero;
            Time.timeScale = 1;
        }

        public static void Sure()
        {
            if (confim != null)
            {
                confim();
                GameObject.Destroy(Messagebox);
                TitleStr = "标题";
                ContentStr = null;
                SureStr = "确定";
                CancelStr = "取消";
                //Time.timeScale = 1;
            }
        }

        public static void Cancle()
        {
            if (cancel != null)
            {
                cancel();
            }
            Result = 2;
            GameObject.Destroy(Messagebox);
            TitleStr = "标题";
            ContentStr = null;
            SureStr = "确定";
            CancelStr = "取消";
            //Time.timeScale =1;
        }

    }


}
